# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Ionut Biru <ibiru@archlinux.org>

pkgname=gjs
pkgver=1.76.0
pkgrel=2
epoch=2
pkgdesc="Javascript Bindings for GNOME"
url="https://wiki.gnome.org/Projects/Gjs"
arch=(x86_64)
license=(GPL)
depends=(
  cairo
  dconf
  gobject-introspection-runtime
  js102
  libsysprof-capture
  readline
)
makedepends=(
  dbus
  git
  gobject-introspection
  meson
)
checkdepends=(
  gtk3
  gtk4
  xorg-server-xvfb
)
provides=(libgjs.so)
_commit=ff2e1b2f15cf246eb391a356a0ac0ea09fafc2e6  # tags/1.76.0^0
source=("git+https://gitlab.gnome.org/GNOME/gjs.git#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd gjs
  git describe --tags | sed 's/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd gjs

  # https://bugs.archlinux.org/task/78549
  # https://gitlab.gnome.org/GNOME/gjs/-/issues/472
  # https://gitlab.gnome.org/GNOME/gjs/-/merge_requests/834
  git cherry-pick -n 1b49495e762e051d60c7e2efda038de9eea4a214
}

build() {
  local meson_options=(
    -D installed_tests=false
  )

  CFLAGS="${CFLAGS/-O2/-O3} -fno-semantic-interposition"
  CXXFLAGS="${CXXFLAGS/-O2/-O3} -fno-semantic-interposition"
  LDFLAGS+=" -Wl,-Bsymbolic-functions"

  arch-meson gjs build "${meson_options[@]}"
  meson compile -C build
}

check() {
  dbus-run-session xvfb-run -s '-nolisten local' \
    meson test -C build --print-errorlogs
}

package() {
  depends+=(libreadline.so)
  meson install -C build --destdir "$pkgdir"
}

# vim:set sw=2 sts=-1 et:
